﻿using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using TimeStamper.DSL;

namespace TimeStamper.SampleWeb
{
    [ServiceContract(Namespace = "")]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ParserService
    {
        //[WebGet()]
        [OperationContract]
        public DateRange ParseScript(string Script)
        {
            var parser = new Parser(new Lexer(new StringCharacterBuffer(Script, 3)));

            if (parser.Errors.Count > 0) throw new Exception(parser.Errors[0]);        
            var dateRange =  parser.Eval();
            if(dateRange.Dates.Count==0) throw new Exception("Dates not parsed");
            return dateRange;
        }

        // Add more operations here and mark them with [OperationContract]
    }
}
